﻿<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8"/>
    <title>页面跳转</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta
            name="viewport"
            content="width=device-width, initial-scale=1, maximum-scale=1"
    />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
    <link rel="stylesheet" href="amis/sdk.css"/>
    <link rel="stylesheet" href="amis/helper.css"/>
    <link rel="stylesheet" href="amis/iconfont.css"/>
    <style>
        html,
        body,
        .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script src="amis/sdk.js"></script>
<script src="Js/Tool.js"></script>
<script type="text/javascript">
    (function () {
        var code = getUrlParam("code");
        if (!code) {
            alert("授权失败，请重新授权!");
            return;
        }
        // alert(code);

        let amis = amisRequire('amis/embed');
        // 通过替换下面这个配置来生成不同页面
        let amisJSON = {
                "type": "page",
                "body": [
                    {
                        "type": "service",
                        "api": {
                            "url": "/api/mp/wxinfo/${code}",
                            "method": "get",
                            adaptor: function (payload, response, api) {
                                // alert(JSON.stringify(payload));

                                if (payload.data.OpenId != null && payload.data.OpenId != '' && payload.data.OpenId != undefined) {
                                    let rurl = localStorage.getItem('rurl');
                                    console.log("获取到了用户信息", payload, response, api, rurl)
                                    localStorage.setItem('openid', payload.data.OpenId);
                                    if (payload.data.UserState == 0) {
                                        // 获取url中的rurl 参数
                                        window.location.href = rurl;
                                    } else {
                                        alert("您的账号还没有通过审核!无法继续浏览信息!");
                                    }
                                } else {
                                    document.title = "用户注册";
                                }
                                return payload;
                            }
                        },
                        body: [
                            {
                                "type": "wrapper",
                                "visibleOn": "${Id!=null&&Id!=''&&Id!=undefined}",
                                "body": [
                                    {
                                        "visibleOn": "${UserState!=0}",
                                        type: "static",
                                        className: "text-xl text-center",
                                        tpl: "您的账号暂未通过审核！<br>请等待审核！"
                                    },
                                    {
                                        "visibleOn": "${UserState==0}",
                                        type: "static",
                                        className: "text-xl text-center",
                                        tpl: "您的账号已经通过审核了！！<br>去浏览信息吧！"
                                    }
                                ]
                            },
                            // {
                            //     "type": "wrapper",
                            //     "visibleOn": "${(Id==null||Id==''||Id==undefined)&&(openid==null||openid==''||openid==undefined)}",
                            //     "body": [
                            //         {
                            //             type: "static",
                            //             className: "text-xl text-center",
                            //             tpl: "获取信息失败，请重新打开！"
                            //         }
                            //     ]
                            // },
                            {
                                "type": "wrapper",
                                "visibleOn": "${(Id==null||Id==''||Id==undefined)&&(openid!=null&&openid!=''&&openid!=undefined)}",
                                "body":
                                    [{
                                        "type": "flex",
                                        "items": {
                                            type: "tpl",
                                            className: "text-xl text-center mb-5 font-bold",
                                            tpl: "用户注册"
                                        }
                                    },
                                        {
                                            "type": "flex",
                                            "items": {
                                                "type": "avatar",
                                                "size": 60,
                                                "src": "${headimgurl}"
                                            }
                                        },
                                        {
                                            "type": "form",
                                            submitText: "提交注册",
                                            "title": "",
                                            "api": {
                                                "method": "post",
                                                url: "/api/user",
                                                data: {
                                                    "Tel": "$Tel",
                                                    "Name": "$Name",
                                                    "CompanyName": "$CompanyName",
                                                    "OpenId": "${openid}",
                                                    "NickName": "${nickname}",
                                                    "HeadImgUrl": "${headimgurl}"
                                                },
                                                adaptor: function (payload, response, api) {
                                                    if (payload.status == 0) {
                                                        alert("注册成功！请等待管理员审核!\r\n您可以关闭此页面了!");
                                                    }
                                                }
                                            },
                                            "body": [
                                                {
                                                    "type": "hidden",
                                                    "name": "openid",
                                                    "label": "微信ID："
                                                },
                                                {
                                                    "type": "static",
                                                    "name": "nickname",
                                                    "label": "昵称："
                                                },
                                                {
                                                    "name": "CompanyName",
                                                    "type": "input-text",
                                                    "label": "公司名称："
                                                },
                                                {
                                                    "type": "input-text",
                                                    "name": "Name",
                                                    "label": "姓名："
                                                },
                                                {
                                                    "name": "Tel",
                                                    "type": "input-text",
                                                    "label": "电话："
                                                }
                                            ]
                                        }
                                    ],

                            }
                        ]
                    }
                ]
            }
        ;
        let amisScoped = amis.embed('#root', amisJSON);
    })
    ();
</script>
</body>
</html>